import store from '@/store';

const storageCenter = {
  // 存储数据
  storageData: function (callback) {
    let jsonString = encodeURIComponent(JSON.stringify(store.state))
    window.localStorage.setItem('vuex', jsonString);
    if (callback) {
      callback();
    }
  },
  // 同步数据
  synchronousData: function (callback) {
    let jsonString = window.localStorage.getItem('vuex');
    if (jsonString && jsonString != '' && jsonString != undefined) {
      let jsonData = JSON.parse(decodeURIComponent(jsonString))
      store.replaceState(jsonData)
    }

    if (callback) {
      callback();
    }
  }
}

export default storageCenter;